package com.dgut.healthreportmanage.service;

import com.dgut.healthreportmanage.mapper.AdminMapper;
import com.dgut.healthreportmanage.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class AdminServiceImpl implements AdminService{
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public int login(String adminName, String password) {
        Admin adminByName = adminMapper.getAdminByName(adminName);
        if (adminByName == null) {
            return 0;
        }
        if (adminByName.getAdminName().equals(adminName) && adminByName.getPassword().equals(password)) {
            if (adminByName.getState() == 0) {
                return 2;
            }
            if (adminByName.getAdminId() == 1) {
                return 3;
            }
            return 1;
        }
        return 0;
    }

    @Override
    public List<Admin> getAllAdmins() {
        return adminMapper.getAllAdmins();
    }

    @Override
    public int update(Admin admin) {
        if (adminMapper.update(admin) == 1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int freeze(int adminId) {
        return adminMapper.freeze(adminId);
    }

    @Override
    public int delete(int adminId) {
        return adminMapper.delete(adminId);
    }
}
